﻿using System;

using System.Collections.Generic;
using System.Text;
using DirectUI.Mobile.UI.Controls.Layout;
namespace DirectUI.Mobile.UI.Controls
{
 public   class DirectUIStackPanel:DirectUIPanel
    {
     private ILayoutEngine layoutEngine;
     public ILayoutEngine LayoutEngine
     {
         get
         {
             return layoutEngine;
         }
         set
         {
             layoutEngine = value;
         }
     }
     public  DirectUIStackPanel()
         : base()
     {
         layoutEngine = new StackLayoutEngine();
         this.Controls.NotifyChanged += new EventHandler(Controls_NotifyChanged);
        this.Controls.ControlAdded+=new EventHandler<ControlEventArgs>(Controls_ControlAdded);
     }

     void Controls_NotifyChanged(object sender, EventArgs e)
     {
         layoutEngine.Layout(this, null);
     }

     void Controls_ControlAdded(object sender, ControlEventArgs e)
     {
        IDirectUIControl c = e.Control;
      //   layoutEngine.Layout(this, null);
         c.SizeChanged += new EventHandler<ChangedEventArgs<System.Drawing.Size>>(c_SizeChanged);
     }

     void c_SizeChanged(object sender, ChangedEventArgs<System.Drawing.Size> e)
     {
         layoutEngine.Layout(this, null);
     }
    }
}
